// pages/person/person.js
var api = require("../../util/util.js")
var service_user = require("../../service/user.js");
var service_parent = require("../../service/parent.js");
var service_son = require("../../service/son.js");
var service_daili = require("../../service/daili.js");
var service_money = require("../../service/money.js");
var service_common = require("../../service/common.js");
var service_version = require("../../service/version.js");
var service_view = require("../../service/view.js");
var service_adv = require("../../service/adv.js");
const apii = require('../../utils/util.js')
const service = require('../../utils/service.js')
Page({
  data: {
    userInfo: {},
    select: false,
    show: false,
    psw: '',
    master_phone:""
  },
  onLoad: function() {
    this.setData({
      master_phone: wx.getStorageSync('userInfo').master_phone
    })
  },
  onShow: function() {
    this.getUserInfo()
  },
  setFocus: function() {
    this.setData({
      focus: true
    })
  },
  // 获取个人信息
  getUserInfo: function() {
    let that = this
    service_common.fetchData(
      service_common.getUrl("user.getUserProfile"), {
        openid: getApp().globalData.userInfo.openid
      },
      function(res) {
        if (res.data.code == 0) {
          console.log(res.data.data)
          if (res.data.data.view_card == 0) {
            that.setData({
              select: false
            })
          } else {
            that.setData({
              select: true
            })
          }
          that.setData({
            userInfo: res.data.data
          })
        } else {
          api.tips(res.data.message)
        }
      },
      "GET"
    )
  },
  // 拨打电话
  callPhone:function(){
    wx.makePhoneCall({
      phoneNumber: this.data.master_phone,
    })
  },
  kefu_: function () {
    service_common.fetchData(
      'https://t.gxmp.henghi.com/uri/wxservice/sendDownloadApp',
      {
        openid: getApp().globalData.userInfo.openid,
        appid: getApp().globalData.app_id
      },
      (res) => {

      },
      "GET"
    )
  },
  checkLogin: function() {
    console.log(wx.getStorageSync('checkLogin'))
    apii.ajax(service.url('checkLogin'), {
      unionid: wx.getStorageSync('shop_data').shop_unionid,
      pwd: this.data.psw
    }, res => {
      if (res.code == 0) {
        let isOpenShop = wx.getStorageSync('shop_data').is_store == 0 ? false : true;
        let popIsShop = wx.getStorageSync('shop_data').is_store == 0 ? true : false;
        this.setData({
          show: false
        })
        wx.setStorageSync("checkLogin", true)
        wx.navigateTo({
          url: `/pages/admin/admin`
        })
      } else {
        wx.showToast({
          title: res.message,
          icon: "none"
        })
        this.setData({
          show: false
        })
      }
    })

  },
  hidebox: function() {
    this.setData({
      show: false
    })
  },
  // 获取密码
  getpsw: function(e) {
    this.setData({
      psw: e.detail.value
    })
  },
  stop_hide: function() {

  },
  // 管理官网
  Gwang: function() {
    wx.navigateTo({
      url: '/pages/manage/index/index',
    })
  },

  // 前往专属导师
  toOther: function(e) {
    var that = this;
    // wx.navigateTo({
    //   url: "../other/other?openid=" + that.data.parent_openid,
    // })
    if (getApp().globalData.userInfo.shareopenid == 0 || getApp().globalData.userInfo.shareopenid == "") {
      wx.showToast({
        title: '无推荐人',
        image: "../../image/no_people.png"
      })
    } else {
      wx.navigateTo({
        url: "../other/other?openid=" + getApp().globalData.userInfo.shareopenid,
      })
    }
  },

  // 编辑个人信息
  toEdit: function(e) {
    wx.navigateTo({
      url: '../edit/edit',
    })
  },
  //前往客服
  toKefu: function() {
    wx.navigateTo({
      url: '../zxkefu/zxkefu',
    })
  },
  // 前往app
  jiaoLiuQun: function() {
    wx.showModal({
      title: '提示',
      content: '需要前去下载APP',
      confirmText: "前往",
      success: function(res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/aApp/aApp',
          })
        }
      }
    })
  },

  // 专属码
  toCode: function(e) {
    service_user.getUserCode();
  },
  goOpenShop: function() {
    if (wx.getStorageSync('checkLogin')) {
      wx.navigateTo({
        url: `/pages/admin/admin`
      })
    } else {
      this.setData({
        show: true
      })
    }

  },
  showCard: function(e) {
    var that = this;
    if (!e.detail.value) {
      wx.showModal({
        title: '提示',
        content: '您的名片将展示',
        success: function(res) {
          if (res.confirm == true) {
            service_user.showCard(function() {
              getApp().globalData.userInfo["view_card"] = 0;
              wx.hideLoading();
              wx.showToast({
                title: '关闭隐藏',
                duration: 400
              })
            });
          } else {
            that.setData({
              select: !e.detail.value
            })
          }
        }
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '您的名片将隐藏',
        success: function(res) {
          if (res.confirm == true) {
            service_user.hideCard(function() {
              getApp().globalData.userInfo["view_card"] = 1;
              wx.hideLoading();
              wx.showToast({
                title: '打开隐藏',
                duration: 400
              })
            });
          } else {
            that.setData({
              select: !e.detail.value
            })
          }
        }
      })
    }
  },

  // 关于有张vip
  toInfo: function(e) {
    // add_form_id(e.detail.formId);
    wx.navigateTo({
      url: '../info/info',
    })
  }
})